package com.newasia.management.controller;/**
 * Created by mic on 2019/8/1.
 */

import com.newasia.commons.result.ResponseData;
import com.newasia.commons.result.ResponseUtil;
import com.newasia.management.IHomepageNavService;
import com.newasia.management.IHomepageService;
import com.newasia.management.constants.ManagementRetCode;
import com.newasia.management.dto.HomepageBanner.*;
import com.newasia.management.dto.HomepageNav.*;
import com.newasia.management.dto.HomepageNavItem.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * lyh
 * 2019/10/24
 */
@Slf4j
@RestController
@RequestMapping("/management")
public class HomepageNavController {

    @Reference(timeout = 3000)
    IHomepageNavService homepageNavService;


    /**主页菜单**/
    /**增*/
    @PostMapping("/nav")
    public ResponseData createNav(@RequestBody CreateNavRequest request, HttpServletRequest httpServletRequest){

        CreateNavResponse response= homepageNavService.createNav(request);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }

    /**增*/
    @PostMapping("/navItem")
    public ResponseData createNavItem(@RequestBody CreateNavItemRequest request, HttpServletRequest httpServletRequest){

        CreateNavItemResponse response= homepageNavService.createNavItem(request);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }

    /**删*/
    @DeleteMapping("/nav/{navId}")
    public ResponseData deleteNav(@PathVariable("navId") Long navId, HttpServletRequest httpServletRequest){

        DeleteNavResponse response= homepageNavService.deleteNav(navId);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }


    /**删*/
    @DeleteMapping("/navItem/{navItemId}")
    public ResponseData deleteNavItem(@PathVariable("navItemId") Long navItemId, HttpServletRequest httpServletRequest){

        DeleteNavItemResponse response= homepageNavService.deleteNavItem(navItemId);

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);
    }

    /**改*/
    @PutMapping("/nav/{navId}")
    public ResponseData changeNav(@PathVariable("navId") Long navId, @RequestBody ChangeNavRequest request, HttpServletRequest httpServletRequest){

        ChangeNavResponse response= homepageNavService.changeNav(navId,request);


        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);

    }

    /**改*/
    @PutMapping("/navItem/{navItemId}")
    public ResponseData changeNavItem(@PathVariable("navItemId") Long navItemId, @RequestBody ChangeNavItemRequest request, HttpServletRequest httpServletRequest){

        ChangeNavItemResponse response= homepageNavService.changeNavItem(navItemId,request);


        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);

    }

    /**查*/
    @GetMapping("/nav")
    public ResponseData nav(HttpServletRequest httpServletRequest){
        GetNavResponse response= homepageNavService.getNavList();

        if(response.getCode().equals(ManagementRetCode.SUCCESS.getCode())){
            return new ResponseUtil().setData(response);
        }
        return  new ResponseUtil().setErrorMsg(response);

    }




}
